const { request, response } = require("express");
const express = require("express");

const app = express();

app.get("/home",(request,response)=>{
    //响应一个页面
    response.sendFile(__dirname +"/index.html")
});
app.get("/data",(request,response)=>{

    response.send("用户数据"); 
});
app.all("/jsonp-server",(request,response)=>{
    const data = {
        exist:1,
        msg:"用户名已存在！"
    };
    let str = JSON.stringify(data);
    response.send(`handle(${str})`); 
});
app.all("/cors-server",(request,response)=>{
    response.setHeader("Access-Control-Allow-Origin","*");
    response.setHeader("Access-Control-Allow-Headers","*");
    response.setHeader("Access-Control-Allow-Method","*");
    response.send("HELLO CORS");
})
app.listen(9000,()=>{
    console.log("服务已经启动！")
})